package com.nacrtstudio.webgiftshop.core.dao.service.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.springframework.transaction.annotation.Transactional;

import com.nacrtstudio.webgiftshop.core.dao.HibernateDao;
import com.nacrtstudio.webgiftshop.core.dao.service.ReadCommand;
import com.nacrtstudio.webgiftshop.model.shop.Gift;

public class ReadCommandImpl<Type> implements ReadCommand<Type> {
	private Class<Type> type;
	private HibernateDao<Session> hibernateDao;
	
	
	public ReadCommand<Type> setType(Class<Type> clazz) {
		this.type = clazz;
		return this;
	}

	public Class<Type> getType() {
		return type;
	}

	public HibernateDao<Session> getHibernateDao() {
		return hibernateDao;
	}


	public void setHibernateDao(HibernateDao<Session> hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

	@Transactional
	public List<Type> execute() {
		return getHibernateDao().get(getType());
	}
	
	@Transactional
	public List<Type> execute(Class<Type> type, Type object) {
		return getHibernateDao().get(type, object);
	}
	
	@Transactional
	public Type execute(Class<Type> searchForType, String property, String value) {
		return (Type) getHibernateDao().getByPropertyValue(searchForType, property, value);
	}
	@Transactional
	public List<Type> execute(Class<Type> class1, String property) {
		return getHibernateDao().getByMaxValue(class1, property);
	}
	@Transactional
	public Type execute(Class<Type> searchForType, String property, Long value) {
		return (Type) getHibernateDao().getByLongValue(searchForType,property,value);
	}
	@Transactional
	public List<Type> getAllAscSortByProperty(Class<Type> class1, String property) {
		return getHibernateDao().getAllAscSortByProperty(class1, property);
	}

}
